package com.datastructure.test.inordertraversal;

import java.util.ArrayList;
import java.util.List;

public class Solution {
    public int[] inorderTraversal (TreeNode root) {
        // write code here
        List<Integer> result = new ArrayList<>();
        infixOrder(result,root);
        int[] data = new int[result.size()];
        for (int i = 0; i < result.size(); i++) {
            data[i] = result.get(i);
        }
        return data;
    }

    public void infixOrder(List<Integer> result,TreeNode root){
        // 递归向左子树前序遍历
        if(root.left != null){
            infixOrder(result,root.left);
        }
        // 输出父结点
        result.add(root.val);
        // 递归向右子树遍历
        if(root.right != null){
            infixOrder(result,root.right);
        }
    }
}
